//axios二次封装
import axios from "axios";
import { useLoginStore } from "../Store/Login";
const Serive = axios.create({
  baseURL: "http://localhost:3000", // 设置请求的基础URL
  timeout: 5000, // 设置请求超时时间
});

// // 请求拦截器
Serive.interceptors.request.use(
  function (config) {
    config.headers.Authorization = localStorage.getItem("accessToken");
    // console.log("axios请求拦截器", config.headers.Authorization);
    return config;
  },
  function (error) {
    return Promise.reject(error);
  }
);

// // 响应拦截器
Serive.interceptors.response.use(
  function (response) {
    if(response.data.code === 403){
        useLoginStore().RefreshToken()
        return response;
    }
    return response;
  },
  function (error) {
    return Promise.reject(error);
  }
);



export default Serive;
